package org.example.infrastructure.repository.remote;

import lombok.RequiredArgsConstructor;
import org.example.infrastructure.persistence.remote.RemoteUrlShortenerGroupPersistence;
import org.example.web.exception.ServerException;
import org.example.web.result.BaseSuccessCode;
import org.example.web.result.ResultInfo;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;

@Repository
@RequiredArgsConstructor
public class RemoteUrlShortenerGroupRepository {
    private final RemoteUrlShortenerGroupPersistence remoteUrlShortenerGroupPersistence;

    public List<String> selectGitListByUserName(String userName){
        ResultInfo<List<String>> resultInfo = remoteUrlShortenerGroupPersistence.selectGitListByUserName(userName);
        if (!Objects.equals(resultInfo.getStatus(), BaseSuccessCode.SUCCESSFUL_OPERATION.code())){
            throw new ServerException("查询分组失败！");
        }
        return resultInfo.getData();
    }
}
